package com.t4.wechat.controller;


import com.t4.common.result.Result;
import com.t4.model.wechat.WechatMenu;
import com.t4.vo.wechat.WechatMenuVo;
import com.t4.wechat.service.WechatMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "公众号管理")
@RestController
@RequestMapping("/admin/wechat/menu")
public class WechatMenuController {

    @Resource
    private WechatMenuService wechatMenuService;

    @ApiOperation(value = "根据id获取菜单")
    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id){
        WechatMenu wechatMenu = wechatMenuService.getById(id);
        return Result.success(wechatMenu);
    }

    @ApiOperation(value = "新增菜单")
    @PostMapping("save")
    public Result save(@RequestBody WechatMenu wechatMenu){
        boolean is_success = wechatMenuService.save(wechatMenu);
        if(is_success){
            return Result.success();
        }else {
            return Result.fail();
        }
    }

    @ApiOperation(value = "修改菜单")
    @PutMapping("update")
    public Result updateById(@RequestBody WechatMenu wechatMenu){
        boolean is_success = wechatMenuService.updateById(wechatMenu);
        if(is_success){
            return Result.success();
        }else {
            return Result.fail();
        }
    }

    @ApiOperation(value = "删除菜单")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id){
        boolean is_success = wechatMenuService.removeById(id);
        if(is_success){
            return Result.success();
        }else {
            return Result.fail();
        }
    }

    @ApiOperation(value = "获取全部菜单")
    @GetMapping("findMenuInfo")
    public Result findMenuInfo(){
        List<WechatMenuVo> wechatMenuVoList = wechatMenuService.findMenuInfo();
        return Result.success(wechatMenuVoList);
    }

    @ApiOperation(value = "同步微信公众号菜单")
    @GetMapping("syncMenu")
    public Result syncMenu(){
        wechatMenuService.syncMenu();
        return Result.success();
    }

    @ApiOperation(value = "删除微信公众号菜单")
    @DeleteMapping("removeMenu")
    public Result removeMenu(){
        wechatMenuService.removeMenu();
        return Result.success();
    }


}
